#ifndef XMLSERVERTHREAD_HH_
#define XMLSERVERTHREAD_HH_
#include "Network.hh"
#include "XmlSocket.hh"
#include "ConnectionState.hh"
#include "../World/User.hh"
#include <boost/noncopyable.hpp>
#include <QtCore>
#include <QtNetwork>
#include <QtXml>

/// \brief Egy kapcsolatot kiszolgáló szál.
class Network::XmlServerThread: public QThread, private boost::noncopyable {
    Q_OBJECT

    /// \brief Szálakat és játékosokat összerendelő adatstruktúra.
    public: typedef QMap< World::pPlayer, pXmlServerThread > ThreadMap;

    /// \brief Szálakat és a játékra váró játékosokat összerendelő adatstruktúra
    public: typedef QMap< World::pUser, pXmlServerThread > ThreadUserMap;

    protected: static QMutex staticLock;

    protected: static bool closeAll;

    protected: static ThreadMap threads;

    protected: static ThreadUserMap nonplayingusers;

    public: static pXmlServerThread select(World::spPlayer player);

    public: static void close_all();

    protected: int const socketDescriptor;

    protected: spXmlSocket socket;

    protected: QSslConfiguration sslConfig;

    protected: ConnectionState state;

    protected: World::spUser user;

    protected: World::spPlayer player;

    public:
    XmlServerThread(
      int socketDescriptor,
      QSslConfiguration const& sslConfig = QSslConfiguration(),
      QObject* parent = 0
    );

    public: ~XmlServerThread();

    public: void run();

    public: spXmlSocket get_socket();

    public: ConnectionState get_state();

    public: void set_state(ConnectionState value);

    public: World::spUser get_user();

    public: void set_user(World::spUser value);

    public: World::spPlayer get_player();

    public: void set_player(World::spPlayer value);

    protected slots: void process_message();

    public: void broadcast_chat_message(QString message);
};

#endif /* XMLSERVERTHREAD_HH_ */
